package com.meiqiongproperty.yiguanjia.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.meiqiongproperty.yiguanjia.R;


/**
 * 条目组合空间 ImageView textView ImageView
 *
 * @author Chen
 * @version V1.0
 * @package com.sameway.cnotes.ui
 * @date 17/1/18
 */
public class DefaultEntryView extends RelativeLayout {
    private String mTextView;
    private Drawable mLeftImagem;
    private Drawable mRightImage;
    private View mRootView;

    private ImageView LeftImage, RightImg;
    private TextView textView;

    public DefaultEntryView(Context context) {
        super(context);
        init(context, null);
    }

    public DefaultEntryView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public DefaultEntryView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        mRootView = LayoutInflater.from(context).inflate(R.layout.view_default_entry_view, this, true);
        LeftImage = (ImageView) mRootView.findViewById(R.id.leftImage);
        textView = (TextView) mRootView.findViewById(R.id.text);

        if (attrs != null) {
            TypedArray ta = context.obtainStyledAttributes(attrs,
                    R.styleable.DefaultEntryView);


            if (ta != null) {
                mTextView = ta.getString(R.styleable.DefaultEntryView_text);
                if (mTextView != null) {
                    textView.setText(mTextView);
                }
                mLeftImagem = ta
                        .getDrawable(R.styleable.DefaultEntryView_leftImg);
                if (mLeftImagem != null) {
                    LeftImage.setImageDrawable(mLeftImagem);
                }
                mRightImage = ta
                        .getDrawable(R.styleable.DefaultEntryView_rightImg);
                ta.recycle();
            }
        }

    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        if (isInEditMode())
            return;
        RightImg = (ImageView) mRootView.findViewById(R.id.leftImage);

        textView = (TextView) mRootView.findViewById(R.id.text);
        textView.setText(mTextView);
    }


    public void setText(String text) {
        textView.setText(text);
    }

    public void setLeftImg(int resId) {
        if (LeftImage != null) {

        }
        LeftImage.setImageResource(resId);
    }


    @Override
    protected void onFocusChanged(boolean gainFocus, int direction,
                                  Rect previouslyFocusedRect) {
        // TODO Auto-generated method stub
        if (gainFocus) {
            super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
        }
    }

    @Override
    public void onWindowFocusChanged(boolean hasWindowFocus) {
        // TODO Auto-generated method stub
        if (hasWindowFocus) {
            super.onWindowFocusChanged(hasWindowFocus);
        }
    }

    @Override
    public boolean isFocused() {
        // TODO Auto-generated method stub
        return true;
    }
}
